package com.shuoyue.ycgk.ui.main.adv;

import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.MainAdv;
import com.shuoyue.ycgk.entity.WelcomeBean;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.ArrayList;

import io.reactivex.Observable;

public interface LauncherAdvContract {
    interface View extends BaseView {

        void setAdv(ArrayList<WelcomeBean> mainAdv);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getLauncherAdv() {
            apply(model.getLauncherAdv())
                    .subscribe(new ApiSubscriber<Optional<ArrayList<WelcomeBean>>>(mView, this) {
                        @Override
                        public void onNext(Optional<ArrayList<WelcomeBean>> option) {
                            super.onNext(option);
                            mView.setAdv(option.getIncludeNull());
                        }
                    });
        }
    }

    class Model {
        Observable<BaseResult<ArrayList<WelcomeBean>>> getLauncherAdv() {
            return RetrofitClient.getInstance().getApi().getLauncherAdv();
        }
    }
}
